package com.sodaopen.crm.common.entity;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AjaxResult {

	private int code;
	private String msg;
	
	@JsonInclude(Include.NON_NULL) 
	private Object data;

	public AjaxResult(){}
	public AjaxResult(int code, String msg){
		this.code = code;
		this.msg = msg;
	}
	public AjaxResult(int code, String msg, Object data){
		this(code, msg);
		this.data = data;
	}

	/**
	 * 请求成功
	 * @param msg
	 * @return
	 */
	public static AjaxResult OK(String msg){
		return new AjaxResult(200, msg);
	}

	public static AjaxResult OK(String msg, Object data){
		return new AjaxResult(200, msg, data);
	}
	
	/**
	 * 创建成功
	 * @param msg
	 * @param data
	 * @return
	 */
	public static AjaxResult CREATED(String msg, Object data){
		return new AjaxResult(201, msg, data);
	}
	
	/**
	 * 删除成功
	 * @param msg
	 * @return
	 */
	public static AjaxResult DELETED(String msg){
		return new AjaxResult(204, msg);
	}
	
	/**
	 * 参数不正确或方法不支持等
	 * @param msg
	 * @return
	 */
	public static AjaxResult BAD_REQUEST(String msg){
		return new AjaxResult(400, msg);
	}
	
	public static AjaxResult BAD_REQUEST(String msg, Object data){
		return new AjaxResult(400, msg, data);
	}
	

	/**
	 * 未授权
	 * @param msg
	 * @return
	 */
	public static AjaxResult UNAUTHORIZED(String msg){
		return new AjaxResult(401, msg);
	}
	
	/**
	 * 禁止访问
	 * @param msg
	 * @return
	 */
	public static AjaxResult FORBIDDEN(String msg){
		return new AjaxResult(403, msg);
	}

	/**
	 * 请求的资源不存在
	 * @param msg
	 * @return
	 */
	public static AjaxResult NOT_FOUND(String msg){
		return new AjaxResult(404, msg);
	}
	
	/**
	 * 内部错误
	 * @param msg
	 * @return
	 */
	public static AjaxResult ERROR(String msg){
		return new AjaxResult(500, msg);
	}
}
